#include <stdio.h>
#include <stdlib.h>

int hauteur(int **grille, int N, int M)
{
	int i,j;
	for ( i = 0 ; i < N ; i++ ) {
		for ( j = 0 ; j < M ; j++ ) {
			if ( grille[i][j] == 1 ) return (N - i);
		}
	}
	return 0;
}

int main(void)
{
   int N, M, i, j;
   int **t;

   scanf("%d %d", &N, &M);
   t = (int **)malloc(N * sizeof (int *));
   for (i = 0 ; i < N ; i++)
   {
      t[i] = (int *)malloc(M * sizeof (int));
      for (j = 0 ; j < M ; j++)
        scanf("%d", &t[i][j]);
   }

   printf("%d\n", hauteur(t, N, M));

   for (i = 0 ; i < N ; i++)
      free(t[i]);
   free(t);
   return 0;
}
